package me.leon.aoplib;

import android.view.View;

/**
 * <p>description：</p>
 * <p>author：Leon</p>
 * <p>date：2019/8/29 0029</p>
 * <p>e-mail：deadogone@gmail.com</p>
 */
public class ClickUtils {
    /**
     * 最近一次点击的时间
     */
    private static long mLastClickTime;
    /**
     * 最近一次点击的控件ID
     */
    private static int mLastClickViewId;
    private static final ClickUtils ourInstance = new ClickUtils();

    public static ClickUtils getInstance() {
        return ourInstance;
    }

    private ClickUtils() {
    }
    /**
     * 是否是快速点击
     *
     * @param v              点击的控件
     * @param intervalMillis 时间间期（毫秒）
     * @return true:是，false:不是
     */
    public boolean isFastDoubleClick(View v, long intervalMillis) {
        int viewId = v.getId();
        long time = System.currentTimeMillis();
        long timeInterval = Math.abs(time - mLastClickTime);
        if (timeInterval < intervalMillis && viewId == mLastClickViewId) {
            return true;
        } else {
            mLastClickTime = time;
            mLastClickViewId = viewId;
            return false;
        }
    }
}
